Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: svg sprite generation #1

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

feat: svg sprite generation #1

wants to merge 20 commits into from

Conversation

amtins
Copy link
Contributor

@amtins amtins commented Jun 9, 2024

Description

Adds SVG sprite generation to customize video.js icons.

Specific Changes proposed

  • The bin folder contains the cli.js file for command-line usage.
  • The icons folder contains all the SVG icons used to generate the sprite.
  • The src folder contains the svg-sprite and SVGO configuration files, as well as the script for generating the sprite.
  • The template folder includes the HTML file used for the preview page, along with a configuration file that can be generated via the CLI.
  • The vjs-svg-sprite folder contains the preview page and the default sprite.
  • The index.js file is only used for development and generating the default sprite.
  • The svg-icons.json file defines the default configuration.
  • The .nvmrc file to specify node version

Adds SVG sprite generation to customize video.js icons

- The `bin` folder contains the `cli.js` file for command-line usage.
- The `icons` folder contains all the SVG icons used to generate the sprite.
- The `src` folder contains the `svg-sprite` and `SVGO` configuration files, as well as the script for generating the sprite.
- The `template` folder includes the HTML file used for the preview page, along with a configuration file that can be generated via the CLI.
- The `vjs-svg-sprite` folder contains the preview page and the default sprite.
- The `index.js` file is only used for development and generating the default sprite.
- The `svg-icons.json` file defines the default configuration.
@mister-ben
Copy link

Great stuff, a couple of quick thoughts

  • A .nvmrc would be good
  • I notice the output is a little smaller than what we currently have in video.js/src/images/icons.svg. Is this just better optimised?
  • It's not too important as long as it is documented, but should the output dir be named something more conventional like dist?

@amtins
Copy link
Contributor Author

amtins commented Jun 15, 2024

@mister-ben I've added the .nvmrc file.

I notice the output is a little smaller than what we currently have in video.js/src/images/icons.svg. Is this just better optimised?

Yes, because I've applied two optimizations, the first directly to the icons and the second directly to the generated sprite, which should further reduce the size of the final sprite.

Individual icon optimization

const optimizedIconSvg = optimizeTempIcon(iconPath, svgoConfig);

Sprite optimization

finalContent = optimizeSprite(contents, svgoCleanConfig);

It's not too important as long as it is documented, but should the output dir be named something more conventional like dist?

Yes, I can also change the destination filename to dist. While we're on the subject, do you have any suggestions for the final filename? To import the sprite, you have to do @videojs/svg-sprite-generator/dist/vjs-sprite-icons.svg. In retrospect, I have mixed feelings about the filename; I think there are still too many characters.

amtins added 2 commits July 27, 2024 12:16
Regenerate `vjs-svg-sprite/index.html` to remove reference to wrong repo.
From now on, the value of `output-dir` is `dist` instead of `vjs-svg-sprite`.

Access to the SVG file will be via the path
`@videojs/svg-sprite-generator/dist/vjs-sprite-icons.svg` instead of
`@videojs/svg-sprite-generator/vjs-svg-sprite/vjs-sprite-icons.svg`.
Copy link

@wseymour15 wseymour15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, nice work! I left a few comments and questions.

Regarding the usage of this repo, is the distributed svg file meant to replace the file here? https://github.com/videojs/video.js/pull/8260/files#diff-56a92727a19631fea08e4d8424bbf11cbf939176723287f3e2947eded506fc83

LICENSE Outdated
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 amtins<amtins.dev@gmail.com>.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to update this file to align with https://github.com/videojs/video.js/blob/main/LICENSE

@@ -0,0 +1,2 @@
node_modules
vjs-sprite-tmp_*

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to include dist in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, yes, in order to replace the player.js import with the file generated by this project. A bit like videojs-icons.css

params: {
attributes: [
{
style: 'display: none'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sure there is good reason, but why do we want to set this style on clean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason is that svg-sprite adds style="position:absolute". So the cleanup is to replace position:absolute with display:none. Currently, display:none is applied via JavaScript and is not present in the icons.svg file. This would allow to remove line 545.

"root-dir": "",
"output-dir": "",
"icons": {
"audio-description": "",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems bit repetitive as a similar structure exists in scg-icons.json. Would it be possible to just move those values here and remove the other file?

It may not be possible as I am unfamiliar with svg-sprite, but figured I would mention it and try to get a better understanding.

Copy link
Contributor Author

@amtins amtins Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lack of a README adds some confusion. To give a bit of context, there are two aspects to this project:

  1. Standardize and simplify the generation of the SVG sprite used by video.js. This would allow us to remove the icons.svg file and replace the import with the file generated by this project. I was inspired by the same philosophy as the font project, which is why this project also provides the final file. So the svg-icons.json file is used to generate the sprite for this project.
  2. Allow developers to easily replace the default icons used by video.js. All of this can be done using the command-line tool. Therefore, svg.config.file.js will serve as a configuration file template for developers to customize the icons.

"vjs-svg-sprite": "./bin/cli.js"
},
"scripts": {
"build": "node index.js",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to think if there are any other scripts we may want to include here.. Would we want to include lint, or maybe clean to remove the dist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the linter as well as husky.

Thank you for taking the time to review this PR and for the comments. ❤️

I am open to any other suggestions or ideas you may have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants